
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>菜单/产品管理</h1>
	<ol class="breadcrumb">
		<li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>
				首页</a></li>
		<li><a href="#">农事管理</a></li>
		<li class="active">菜单/产品管理</li>
	</ol>
</section>

<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box box-primary">
				<div class="box-body">
					<div class="row">
						<div class="col-sm-2">
							<div class="dataTables_length">
								<label>
									<select class="form-control input-sm pageSize" style="width:auto;">
										<option>10</option>
										<option>20</option>
										<option>30</option>
										<option>30</option>
										<option>40</option>
									</select>
									记录/页
								</label>
							</div>
						</div>
						<div class="col-sm-10">
							<div class="dataTables_filter" id="searchDiv">
								<input type="search" placeholder="请输入产品名称" title="产品名称" name="productName"
									   class="form-control">
								<input type="search" placeholder="请输入产地" title="产地" name="productArea"
									   class="form-control">
								<input type="search" placeholder="请输入储藏方式" title="储藏方式" name="storageMethod"
									   class="form-control">
								<select  type="search"  title="产品种类" name="productTypeId" class="form-control select2"></select>
								<select  type="search"  title="负责人" name="createUserId" class="form-control select2" hide></select>


								<div class="btn-group">
									<button type="button" class="btn btn-primary" data-btn-type="search">查询</button>
								</div>
								<div class="btn-group">
									<button type="button" class="btn btn-default" data-btn-type="add">新增</button>
								</div>
							</div>
						</div>
					</div>


					<table id="check_table" class="table table-bordered table-striped table-hover" style="margin-bottom:20px;">
						<thead>
						<tr>
							<th name="id" style="display:none;">id</th>
							<th name="productName">产品名称</th>
							<th name="storageMethod">储藏方式</th>
							<th name="productArea">产地</th>
							<th name="productType">产品类型</th>
							<th name="createUsername">负责人</th>
							<th name="">功能选项</th>
						</tr>
						</thead>
						<tbody></tbody>
					</table>
					<div class="paging"></div>
				</div>
			</div>
		</div>
	</div>
	</div>
</section>

<script>
	$(function() {
        AsyncGet("${basePath}/manager/user/getUserRole",null,function (value) {
            if(value.data.role!="超级管理员"){
                $("#searchDiv [hide]").next().hide();
            }
        })

        $(".dataTables_filter [name='createUserId']").loadSelect2(
            "${basePath}/root/function/getBackgroundManagerList",
            "请输入姓名查询",2,"username","username");
        $(".dataTables_filter [name='productTypeId']").loadSelect2(
            "${basePath}/manager/product/getProductTypeByName",
            "请输入名称查询",1,"name","name");

        var table=initTable("${basePath}/manager/product/getProductList",
            $(".content #searchDiv"),
            $(".content table"),
            $(".content .pageSize"),
            $(".content .paging"));
        var param={
            htmlUrl:"${basePath}/function/manager/product/productForm",
            getEntityUrl:"${basePath}/manager/product/getProductInfo",
            deleteEntityUrl:"${basePath}/manager/product/deleteProduct",
            editTitle:"编辑产品信息",
            addTitle:"添加产品",
            addButton:$("[data-btn-type='add']"),
            table:$(".content table"),
            getEntityBefore:function (value) {
                if(value.createUserId!=null){
                    var option=$("<option></option>");
                    option.attr("value",value.createUserId);
                    option.text(value.createUsername);
                    $("#productForm [name='createUserId']").empty().append(option);
				}
                if(value.productTypeId!=null){
                    var option=$("<option></option>");
                    option.attr("value",value.productTypeId);
                    option.text(value.productType);
                    $("#productForm [name='productTypeId']").empty().append(option);
                }
            },
            getEntityCallback:function (value) {
                $('#EditEntity').find("form img").attr("src",
					"${basePath}/manager/product/getProductImage?path="+value.pictureAddress).show();
            },
            addCallback:function () {
                $('#EditEntity').find("form img").hide().attr("src","");
            }
		};
        EditEntity(param,table.search);

        $('#EditEntity').find(".modal-footer button:last").show().unbind("click").click(function(){
            var formData=getFileFormData($('#EditEntity').find("form"));
            ajaxPostFile("${basePath}/manager/product/editProduct",formData,function (value) {
                if(value.code==0){
                    ShowMessage(value.msg);
                    $('#EditEntity').modal("hide");
                    table.search();
                }else{
                    ErrMessage(value.msg);
                }
            })

        });
    });
</script>
